import { post, get } from '@/utils/request';
import { Permission} from '@/pages/backhub/common/permission/store/permissionTypes';

/**
 * 获取权限列表
 * @returns 权限列表
 */
export const getPermissionList = async (): Promise<Permission[]> => {
  return get(`/engine/starhub/permission/getList`);
};

/**
 * 获取权限列表
 * @returns 权限列表
 */
export const getActivePermission = async (): Promise<any[]> => {
  return get(`/engine/starhub/permission/getActivePermission`);
};

/**
 * 获取菜单列表
 * @returns 菜单列表
 */
export const getActiveMenu = async (): Promise<any[]> => {
  return get(`/engine/starhub/menu/getActiveMenu`);
};

/**
 * 获取菜单列表
 * @returns 菜单列表
 */
export const getActiveMenuTree = async (): Promise<any[]> => {
  return get(`/engine/starhub/menu/getActiveMenuTree`);
};

/**
 * 获取角色列表
 * @returns 角色列表
 */
export const getActiveRole = async (): Promise<any[]> => {
  return get(`/engine/starhub/role/getActiveRole`);
};


/**
 * 获取权限
 * @returns 权限信息
 */
export const getInfo = async (id: string): Promise<Permission[]> => {
  return get(`/engine/starhub/permission/getInfo/${id}`);
};

/**
 * 创建权限
 * @param data 权限数据
 * @returns 创建的权限
 */
export const createPermission = async (data: Partial<Permission>): Promise<Permission> => {
  return post(`/engine/starhub/permission/add`, data);
};

/**
 * 更新权限
 * @param id 权限ID
 * @param data 更新的数据
 * @returns 更新后的权限
 */
export const updatePermission = async (id: string, data: Partial<Permission>): Promise<Permission> => {
  data.id = id ;
  return post(`/engine/starhub/permission/update`, data);
};

/**
 * 删除权限
 * @param id 权限ID
 */
export const deletePermission = async (ids: string): Promise<void> => {
  return post(`/engine/starhub/permission/delete`, { ids });
};
